package com.open.pokergames.comm.userCenter

import android.os.Bundle
import android.view.View
import com.jiangyy.easydialog.CommonDialog
import com.open.pokergames.R
import com.open.pokergames.base.activity.EventBusTitleBaseActivity
import com.open.pokergames.comm.repository.cache.LocalCache
import com.open.pokergames.comm.repository.entity.LoginDto
import com.open.pokergames.comm.repository.entity.ResultInfo
import com.sinothk.android.utils.XUtils
import kotlinx.android.synthetic.main.activity_setting.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class SettingActivity : EventBusTitleBaseActivity(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_setting)
        setViewTitle("设置")

        setListener()
    }

    private fun setListener() {
        exitBtn.setOnClickListener(this)
    }

    override fun onClick(v: View) {
        when (v) {
            exitBtn -> {
                CommonDialog.Builder(this)
                    .setCancelable(false)
                    .setTitle("退出提示")
                    .setMessage("确定退出游戏吗？")
                    .setPositiveButton("退出") {
                        LocalCache.logout()
                        XUtils.page().finishAll()
                        XUtils.intent().openActivity(this, WelcomeActivity::class.java)
                            .start()
                    }.setNegativeButton("取消") {
                    }.show()
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public fun loginCallback(resultInfo: ResultInfo<LoginDto>) {

//        if (resultInfo.eventType != "register") {
//            return
//        }
//
//        when (resultInfo.code) {
//            ResultInfo.SUCCESS -> {
//                LocalCache.setLoginUser(resultInfo.data)
//                LocalCache.setAutoLogin(true)
//                XUtils.intent().openActivity(this@RegisterActivity, MainActivity::class.java)
//                    .finish(true).start()
//            }
//            else -> {
//                XUtils.toast().show(resultInfo.msg)
//            }
//        }
    }



}